const JWT = require('../controller/JWT');

module.exports =function auth(req, res, next){
    const { authorization = '' } = req.headers;
    if(!authorization) {
      return res.send({
          status: 401,
          msg:'请先登录'
      })
    }
    const token = authorization.replace('Bearer ', '');
    const info = JWT.verify(token);
    if (info) {
      req.profile = info;
    } else {
      return res.send({
          status: 401,
          msg:'token过期，请重新登录'
      })
    }
    next();
  };
  